package com.zhouz.activiti.utils;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;

import lombok.extern.java.Log;

@Log
public class FontCopyUtil {

	/** 复制文件的方法 */
	public void copyFile() {
		log.info("复制宋体字体的文件开始------------");
		try {
			String systemFilePath = System.getProperty("java.home")+"/lib/fonts";
			int bytesum = 0;
			int byteread = 0;
			File systemFile = new File(systemFilePath);
			if (systemFile.exists()) {
				String fallBackPath = "/fallback";
				File fallBackDir = new File(systemFilePath + fallBackPath);
				if (!fallBackDir.exists()) {
					fallBackDir.mkdir();
				}
				InputStream ttcInputStream = this.getClass().getClassLoader().getResourceAsStream("simsun.ttc");
				InputStream ttfInputStream = this.getClass().getClassLoader().getResourceAsStream("simsun.ttf");
			
				FileOutputStream ttcfs = new FileOutputStream(
						systemFilePath + fallBackPath + File.separator + "simsun.ttc");
				FileOutputStream ttffs = new FileOutputStream(
						systemFilePath + fallBackPath + File.separator + "simsun.ttf");
				byte[] buffer = new byte[1444];
				while ((byteread = ttcInputStream.read(buffer)) != -1) {
					bytesum += byteread; // 字节数 文件大小
					ttcfs.write(buffer, 0, byteread);
				}
				ttcInputStream.close();
				ttcfs.close();
				bytesum = 0;
				byteread = 0;
				byte[] buffer1 = new byte[1444];
				while ((byteread = ttfInputStream.read(buffer1)) != -1) {
					bytesum += byteread; // 字节数 文件大小
					ttffs.write(buffer1, 0, byteread);
				}
				ttfInputStream.close();
				ttffs.close();
			} else {
				log.info("不存在[" + systemFilePath + "]的系统路径");
			}
		} catch (Exception e) {
			log.info("复制文字字体失败");
			e.printStackTrace();
		}
		log.info("复制宋体字体的文件结束");
	} 

}
